﻿<Window x:Class="LabyWPF3D.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:p="http://www.codeplex.com/perspective"
		xmlns:t="clr-namespace:_3DTools;assembly=3DTools"
		x:Name="window"
        Title="3D Labyrinth"
		WindowStartupLocation="CenterScreen"
		Height="700" Width="1000" ResizeMode="NoResize" Icon="/LabyWPF3D;component/Images/icon.ico" Closing="window_Closing">
	<!-- Global resources -->
	<Window.Resources>
		<Style TargetType="{x:Type TextBlock}">
			<Setter Property="HorizontalAlignment" Value="Center" />
			<Setter Property="VerticalAlignment" Value="Center" />
		</Style>
		<Style x:Key="slider">
			<Setter Property="Slider.Orientation" Value="Vertical" />
			<Setter Property="Slider.Height" Value="140.0" />
			<Setter Property="Slider.HorizontalAlignment" Value="Center" />
			<Setter Property="Slider.VerticalAlignment" Value="Center" />
			<Setter Property="Slider.AutoToolTipPlacement" Value="TopLeft" />
		</Style>
		<Style x:Key="ZoomSlider">
			<Setter Property="Slider.Orientation" Value="Horizontal" />
			<Setter Property="Slider.Width" Value="90.0" />
			<Setter Property="Slider.HorizontalAlignment" Value="Center" />
			<Setter Property="Slider.VerticalAlignment" Value="Center" />
			<Setter Property="Slider.AutoToolTipPlacement" Value="TopLeft" />
		</Style>
	</Window.Resources>
	<Grid Background="#FFF9F9F9">
		<!-- Grid -->
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto" />
			<RowDefinition />
			<RowDefinition Height="Auto" />
		</Grid.RowDefinitions>
		<Grid.ColumnDefinitions>
			<ColumnDefinition />
			<ColumnDefinition Width="Auto" />
		</Grid.ColumnDefinitions>
		<!-- Menu -->
		<Menu IsMainMenu="True" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" Height="24" Background="#F9F9F9">
			<!-- File menu -->
			<MenuItem Header="File">
				<MenuItem Header="Open labyrinth" Name="OpenLabMenuItem" Click="OpenLabMenuItem_Click">
					<MenuItem.Icon>
						<Image Source="/LabyWPF3D;component/Images/open.png" />
					</MenuItem.Icon>
				</MenuItem>
				<Separator />
				<MenuItem Header="Open solution" IsEnabled="False" Name="OpenSolutionMenuItem" Click="OpenSolutionMenuItem_Click">
					<MenuItem.Icon>
						<Image Source="/LabyWPF3D;component/Images/open.png" />
					</MenuItem.Icon>
				</MenuItem>				
				<MenuItem Header="Save solution" IsEnabled="False" Name="SaveSolutionMenuItem" Click="SaveSolutionMenuItem_Click">
					<MenuItem.Icon>
						<Image Source="/LabyWPF3D;component/Images/save.png" />
					</MenuItem.Icon>
				</MenuItem>
				<Separator />
				<MenuItem Header="Exit" Click="MenuItem_Click">
					<MenuItem.Icon>
						<Image Source="/LabyWPF3D;component/Images/exit.png" />
					</MenuItem.Icon>
				</MenuItem>
			</MenuItem>
			<!-- Edit menu -->
			<MenuItem Header="Edit">
				<MenuItem Header="Reload" Name="ReloadMenuItem" Click="ReloadMenuItem_Click" IsEnabled="False">
					<MenuItem.Icon>
						<Image Source="/LabyWPF3D;component/Images/reload.png" />
					</MenuItem.Icon>
				</MenuItem>
				<MenuItem Header="Use previous solution" IsEnabled="False" Name="SolutionMenuItem" Click="SolutionMenuItem_Click" IsCheckable="True">
					<MenuItem.Icon>
						<Image Source="/LabyWPF3D;component/Images/solution.png" />
					</MenuItem.Icon>
				</MenuItem>
                <MenuItem Header="Edit Latency" Name="EditLatencyMenuItem" Click="EditLatencyMenuItem_Click" />
			</MenuItem>
			<!-- View menu -->
			<MenuItem Header="View">
				<MenuItem Header="Toogle 3D Axis" Name="AxisMenuItem" Click="AxisMenuItem_Click" IsCheckable="True" IsChecked="False">
					<MenuItem.Icon>
						<Image Source="/LabyWPF3D;component/Images/axis.png" />
					</MenuItem.Icon>
				</MenuItem>				
				<MenuItem Header="Toogle correct path" Name="CorrectPathMenuItem" IsCheckable="True" IsChecked="True" IsEnabled="False" Click="CorrectPathMenuItem_Click">
					<MenuItem.Icon>
						<Image Source="/LabyWPF3D;component/Images/correct.png" />
					</MenuItem.Icon>
				</MenuItem>
				<Separator />
				<MenuItem Header="Toogle console" Name="ConsoleMenuItem" Click="ConsoleMenuItem_Click" IsCheckable="True" IsChecked="True">
					<MenuItem.Icon>
						<Image Source="/LabyWPF3D;component/Images/consoleToogle.png" />
					</MenuItem.Icon>
				</MenuItem>
				<MenuItem Header="Toogle camera controls" Name="CameraMenuItem" IsCheckable="True" IsChecked="True" Click="CameraMenuItem_Click">
					<MenuItem.Icon>
						<Image Source="/LabyWPF3D;component/Images/cameraToogle.png" />
					</MenuItem.Icon>
				</MenuItem>
			</MenuItem>
			<!-- Run menu -->
			<MenuItem Header="Run">
				<MenuItem Header="Solve" IsEnabled="False" Name="ExecMenuItem" Click="ExecMenuItem_Click">
					<MenuItem.Icon>
						<Image Source="/LabyWPF3D;component/Images/run.png" />
					</MenuItem.Icon>
				</MenuItem>
				<MenuItem Header="Stop" IsEnabled="False" Name="StopMenuItem" Click="StopMenuItem_Click">
					<MenuItem.Icon>
						<Image Source="/LabyWPF3D;component/Images/stop.png" />
					</MenuItem.Icon>
				</MenuItem>			
			</MenuItem>			
			<!-- Help menu -->
			<MenuItem Header="Help">
				<MenuItem Header="About" Click="MenuItem_Click_1">
					<MenuItem.Icon>
						<Image Source="/LabyWPF3D;component/Images/about.png" />
					</MenuItem.Icon>
				</MenuItem>
			</MenuItem>
		</Menu>
		<!-- Console -->
		<TabControl Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Height="200" BorderBrush="#FFAEB0B6" Background="#FFF9F9F9" Name="ConsoleTab">
			<TabItem>
				<TabItem.Header>
					<StackPanel Orientation="Horizontal" MouseLeftButtonDown="TabItem_MouseLeftButtonDown">
						<Image Source="/LabyWPF3D;component/Images/console.png" Height="16" Width="16" />
						<TextBlock Margin="3 0 0 0">Console</TextBlock>
					</StackPanel>
				</TabItem.Header>
				<ScrollViewer VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Disabled" Name="consoleScrollBar" Height="166" FontWeight="Normal">
					<TextBox IsReadOnly="True" Name="Cons" />
				</ScrollViewer>
			</TabItem>
		</TabControl>
		<!-- Camera controls -->
		<TabControl Grid.Row="1" Grid.Column="1" Height="Auto" Name="CameraTab" BorderBrush="#FFAEB0B6" Background="#FFF9F9F9" Width="160" TabStripPlacement="Left">
			<TabControl.Resources>
				<Style TargetType="{x:Type TabItem}">
					<Setter Property="Padding" Value="4" />
					<Setter Property="HeaderTemplate">
						<Setter.Value>
							<DataTemplate>
								<ContentPresenter Content="{TemplateBinding Content}">
									<ContentPresenter.LayoutTransform>
										<RotateTransform Angle="270" />
									</ContentPresenter.LayoutTransform>
								</ContentPresenter>
							</DataTemplate>
						</Setter.Value>
					</Setter>
				</Style>
			</TabControl.Resources>
			<TabItem>
				<TabItem.Header>
					<StackPanel Orientation="Horizontal" MouseLeftButtonDown="TabItem_MouseLeftButtonDown_1">
						<Image Source="/LabyWPF3D;component/Images/camera.png" Height="16" Width="16" />
						<TextBlock Margin="3 0 0 0">Camera Controls</TextBlock>
					</StackPanel>
				</TabItem.Header>
				<StackPanel  Width="auto" Height="auto" Background="Transparent" >
					<!-- Rotation sliders -->
					<GroupBox Header="Rotation" Margin="4.0" Height="auto" Width="auto">
						<!-- Rotation sliders grid -->
						<Grid >
							<Grid.ColumnDefinitions>
								<ColumnDefinition Width="*" />
								<ColumnDefinition Width="26*" />
								<ColumnDefinition Width="27*" />
								<ColumnDefinition Width="27*" />
							</Grid.ColumnDefinitions>
							<Grid.RowDefinitions>
								<RowDefinition />
								<RowDefinition />
								<RowDefinition />
							</Grid.RowDefinitions>
							<!-- Rotation sliders labels -->
							<TextBlock Text="X" Grid.Column="1" Margin="9,0,10,0" />
							<TextBlock Text="Y" Grid.Column="2" />
							<TextBlock Text="Z" Grid.Column="3" />
							<!-- Each of rotation sliders -->
							<Slider x:Name="sliderX" Grid.Column="1" Grid.Row="1" Minimum="-180.0" Maximum="180.0" Value="-77" Style="{StaticResource slider}" Margin="1,0,3,0" />
							<Slider x:Name="sliderY" Grid.Column="2" Grid.Row="1" Minimum="-180.0" Maximum="180.0" Value="-20" Style="{StaticResource slider}"/>
							<Slider x:Name="sliderZ" Grid.Column="3" Grid.Row="1" Minimum="-180.0" Maximum="180.0" Value="55" Style="{StaticResource slider}"/>
						</Grid>
					</GroupBox>
					<!-- Moving sliders -->
					<GroupBox Header="Position" Margin="4.0" Height="auto" Width="auto">
						<!-- Moving sliders grid -->
						<Grid>
							<Grid.ColumnDefinitions>
								<ColumnDefinition />
								<ColumnDefinition />
								<ColumnDefinition />
							</Grid.ColumnDefinitions>
							<Grid.RowDefinitions>
								<RowDefinition />
								<RowDefinition />
								<RowDefinition />
							</Grid.RowDefinitions>
							<!-- Moving labels -->
							<TextBlock Text="X" Grid.Column="0" Grid.Row="0"/>
							<TextBlock Text="Y" Grid.Column="1" Grid.Row="0"/>
							<TextBlock Text="Z" Grid.Column="2" Grid.Row="0"/>
							<!-- Each of moving sliders -->
							<Slider x:Name="sliderX1" Grid.Column="0" Grid.Row="1" Minimum="-20" Maximum="20" Value="8" Style="{StaticResource slider}"/>
							<Slider x:Name="sliderY1" Grid.Column="1" Grid.Row="1" Minimum="-20" Maximum="20" Value="9" Style="{StaticResource slider}"/>
							<Slider x:Name="sliderZ1" Grid.Column="2" Grid.Row="1" Minimum="-20" Maximum="20" Value="9" Style="{StaticResource slider}"/>
						</Grid>
					</GroupBox>
					<!-- Zoom Slider -->
					<GroupBox Header="Zoom" Margin="4.0" Height="auto" Width="auto">
						<Slider x:Name="sliderZoom" IsDirectionReversed="True" Minimum="1" Maximum="100" Value="50" Style="{StaticResource ZoomSlider}" SelectionEnd="100" Interval="1" FlowDirection="RightToLeft" />
					</GroupBox>
				</StackPanel>
			</TabItem>
		</TabControl>
		<!-- ViewPort -->
		<Canvas Name="Canvas" MouseWheel="Viewport3D_MouseWheel" Background="Transparent" Grid.Column="0" Grid.Row="1" MouseMove="Canvas_MouseMove" MouseLeftButtonDown="Canvas_MouseLeftButtonDown" MouseLeftButtonUp="Canvas_MouseLeftButtonUp" />
		<Viewport3D Grid.Column="0" Grid.Row="1" Name="ViewPort">
			<!-- Camera -->
			<Viewport3D.Camera>
				<!-- Camera's Default position -->
				<PerspectiveCamera 	  
                LookDirection="-10.0, -2.0, -10.0"
                NearPlaneDistance="1.0" 
                FarPlaneDistance="100.0"
                Position="10.0, 3.0, 10.0" 
                FieldOfView="{Binding ElementName=sliderZoom, Path=Value}"
				x:Name="Camera">
					<PerspectiveCamera.Transform>
						<Transform3DGroup>
							<!-- Rotationion by X -->
							<RotateTransform3D>
								<RotateTransform3D.Rotation>
									<AxisAngleRotation3D 
                                Axis="1.0, 0.0, 0.0" 
                                Angle="{Binding ElementName=sliderX, Path=Value}"/>
								</RotateTransform3D.Rotation>
							</RotateTransform3D>
							<!-- Rotationion by Y -->
							<RotateTransform3D>
								<RotateTransform3D.Rotation>
									<AxisAngleRotation3D 
                                Axis="0.0, 1.0, 0.0" 
                                Angle="{Binding ElementName=sliderY, Path=Value}"/>
								</RotateTransform3D.Rotation>
							</RotateTransform3D>
							<!-- Rotationion by Z -->
							<RotateTransform3D>
								<RotateTransform3D.Rotation>
									<AxisAngleRotation3D 
                                Axis="0.0, 0.0, 1.0" 
                                Angle="{Binding ElementName=sliderZ, Path=Value}"/>
								</RotateTransform3D.Rotation>
							</RotateTransform3D>
							<!-- Position -->
							<TranslateTransform3D  OffsetX="{Binding ElementName=sliderX1, Path=Value}"/>
							<TranslateTransform3D  OffsetY="{Binding ElementName=sliderY1, Path=Value}"/>
							<TranslateTransform3D  OffsetZ="{Binding ElementName=sliderZ1, Path=Value}"/>
						</Transform3DGroup>
					</PerspectiveCamera.Transform>
				</PerspectiveCamera>
			</Viewport3D.Camera>
			<Viewport3D.Children>
				<!-- Light -->
				<ModelVisual3D>
					<ModelVisual3D.Content>
						<Model3DGroup>
							<AmbientLight />
						</Model3DGroup>
					</ModelVisual3D.Content>
				</ModelVisual3D>
				<!-- 3D Axis -->
				<p:XyzAxis3D Signed="True" x:Name="Axis" Visibility="Hidden">
					<p:XyzAxis3D.Transform>
						<Transform3DGroup>
							<ScaleTransform3D ScaleX="5" ScaleY="5" ScaleZ="5" />
						</Transform3DGroup>
					</p:XyzAxis3D.Transform>
				</p:XyzAxis3D>
				<!-- Labyrinth walls -->
				<ModelVisual3D x:Name="Walls">
				</ModelVisual3D>
				<!-- Labyrinth path -->
				<ModelVisual3D x:Name="Path">
				</ModelVisual3D>
				<!-- Ball position -->
				<ModelVisual3D x:Name="Figure">
				</ModelVisual3D>
				<!-- Correct path -->
				<ModelVisual3D x:Name="CorrectPath">
				</ModelVisual3D>	
			</Viewport3D.Children>
		</Viewport3D>
	</Grid>
</Window>
